/**
 * 
 */
package functii.elementare;

import Interpretor.Context;
import arbori.Nod;
import functii.Functie;
import operatori.Ori;

public class Putere extends Nod {

	public String concatTermeni(String aux1, String aux2) 
	{
		if (aux2 == "1")
			return aux1;
		if (Double.parseDouble(aux2) < 0)
			return "1/" + "(" + aux1 + ")" + "^"
					+ aux2.substring(1);
		return "("+aux1 + "^" + aux2+")";
	}
	public static String concatTermens(String aux1, String aux2) 
	{
		if (aux2 == "1")
			return aux1;
		if (Double.parseDouble(aux2) < 0)
			return "1/" + "(" + aux1 + ")" + "^"
					+ aux2.substring(1);
		return "("+aux1 + "^" + aux2+")";
	}
	
	public void interpret(Context cont) {
		cont.actual(this);
	}
	
/*
	public String toString() {
		if (fStang == null)
			System.exit(1);
		return concatTermeni(fStang.toString(), new Constanta(exponent));
	}

	public static String concatTermeni(String aux1, Constanta cons) {
		if (cons.calcul() == 1)
			return aux1;
		if (cons.calcul() < 0)
			return "1/" + "(" + aux1 + ")" + "^"
					+ cons.toString().indexOf(1, cons.toString().length() - 1);
		return aux1 + "^" + cons.toString();
	}
	

	public static double Calcul(double baza, Constanta cons) {
		if (baza == 0)
			if (cons.calcul() < 0) {
				System.err.println("error: division by zero");
				System.exit(1);
			} else
				return 0;
		return Math.pow(baza, cons.calcul());
	}

	public double calcul() {
		if (fStang == null)
			System.exit(1);
		return Calcul(fStang.calcul(), new Constanta(exponent));
	}

	public double calculDerivata() {
		if (fStang == null)
			System.exit(1);
		return Ori.Calcul(exponent, Ori.Calcul(fStang.calculDerivata(), Putere
				.Calcul(fStang.calcul(), new Constanta(exponent - 1))));
	}

	public String derivare() {
		if (fStang == null)
			System.exit(1);
		return Ori.ConcatTermeni(new Constanta(exponent).toString(), Ori
				.ConcatTermeni(fStang.derivare(), Putere.concatTermeni(fStang
						.toString(), new Constanta(exponent - 1))));
	}
*/
}
